package com.qst.crop.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qst.crop.dao.QuestionDao;
import com.qst.crop.entity.Order;
import com.qst.crop.entity.Question;
import com.qst.crop.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionDao questionDao;
    @Override
    public PageInfo<Question> findAllQues(Integer pageNum){
        //PageHelper.startPage方法会将分页信息放入ThreadLocal中，但是 PageHelper 方法调用后紧跟查询方法，就是安全的，因为查询方法后清除了Threadlocal里的值。
        PageHelper.startPage(pageNum,30);
        List<Question> questions =  questionDao.findAllQues();
        PageInfo<Question> questionPageInfo = new PageInfo<>(questions);
        //调用dao进行查询
        return questionPageInfo;
    }

    @Override
    public PageInfo<Question> findPageQues(String keys,Integer pageNum){
        PageHelper.startPage(pageNum,30);
        List<Question> questions =  questionDao.findPageQues(keys);
        PageInfo<Question> questionPageInfo = new PageInfo<>(questions);
        return questionPageInfo;
    }


    @Override
    public Question selectId(Integer id){

        return questionDao.selectId(id);
    }

    @Override
    public int add(Question question){
        return questionDao.add(question);
    }

    @Override
    public List<Question> selectByKindAsUser(String username){
        return questionDao.selectByKindAsUser(username);
    }
    @Override
    public List<Question> selectByKindAsExport(String username){
        return questionDao.selectByKindAsExport(username);
    }

    @Override
    public int update(Question question){
        return questionDao.update(question);
    }

    @Override
    public int delById(Integer id){
        return questionDao.delById(id);
    }
}
